# coding=utf-8
# @Time: 2023/2/23 14:22
# @Author: zyg
# email: zhaoyiguang@lecent.cn
import time
from time import sleep

import requests
from selenium.webdriver.common.by import By

from base.ObjectMap import ObjectMap
from base.RegisterBase import RegisterBase
from common.yaml_config import GetConfig
from config.driver_config import DriverConfig
from logs.log import log


class RegisterPage(RegisterBase, ObjectMap):
    def register_input_value(self, driver, input_placeholder, input_value):
        """
        注册页输入 值
        :param driver:
        :param input_placeholder:
        :param input_value:
        :return:
        """
        log.info("输入" + input_placeholder + "为：" + str(input_value))
        input_xpath = self.register_input(input_placeholder)
        return self.element_fill_value(
            driver, By.XPATH, input_xpath, input_value)

    def select_radio_click(self, driver, radio_value):
        """
        选择性别
        :param driver:
        :param radio_value:
        :return:
        """
        log.info("选择的性别为：" + str(radio_value))
        radio_xpath = self.register_radio_box(radio_value)
        return self.element_click(driver, By.XPATH, radio_xpath)

    def register_button_click(self, driver, button_value):
        """
        点击确定按钮
        :param driver:
        :param button_value:
        :return:
        """
        log.info("点击：" + str(button_value) + "按钮")
        radio_xpath = self.register_button(button_value)
        return self.element_click(driver, By.XPATH, radio_xpath)

    def register(self, driver, user):
        log.info("跳转至注册页")
        self.element_to_url(driver, "/register")
        username, password, email, phone, radio, school = GetConfig(
        ).get_registe_data(user)
        print(username, password, email, phone, radio, school)
        # username = time.strftime("%Y%m%d%H%M%S", time.localtime(time.time()))
        print(username)
        self.register_input_value(driver, "用户名", username)
        self.register_input_value(driver, "密码", password)
        self.register_input_value(driver, "邮箱", email)
        self.register_input_value(driver, "手机号", phone)
        self.register_input_value(driver, "所属大学", school)
        self.select_radio_click(driver, radio)
        self.register_button_click(driver, "注册")


# if __name__ == '__main__':
#     driver = DriverConfig().driver_config()
#     RegisterPage().register(driver, "user_a")
